import { Module } from '@nestjs/common';
import { GroupController } from '../controller/group.controller';
import { GroupService } from '../service/group.service';
import { MongooseModule } from '@nestjs/mongoose';
import { Group, GroupSchema } from '../entities/group.entity';
import { GroupUser, GroupUserSchema } from 'src/entities/group-user.entity';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname, join } from 'path';

@Module({
  imports: [
    MongooseModule.forFeature([
      { name: Group.name, schema: GroupSchema },
      { name: GroupUser.name, schema: GroupUserSchema },
    ]),
    MulterModule.register({
      storage: diskStorage({
        destination: join(__dirname, '../../', '/public/upload/group'), // 存放目录
        filename: (req, file, callback) => {
          const fileName = `${new Date().getTime() + extname(file.originalname)}`
          return callback(null, fileName)
        }
      })
    })
  ],
  controllers: [GroupController],
  providers: [GroupService],
})
export class GroupModule {}
